#include "junix.h"
using namespace std;

struct A
{
	int i;
	int j;

	A(int ii=0,int jj=0):i(ii),j(jj){ }

	int geti(){ return i;}
    void print_i()
    {
    	cout<<i<<" ";
    }

    void print_j()
    {
    	cout<<j<<" ";
    }
};

int main(int argc, char **argv)
{
	srand( time(0));
	vector<A> va;

	for(int i=0;i<20;i++)
	{
		va.push_back( A(rand()%20,rand()%20));
	}

	for_each(va.begin(),va.end(),mem_fun_ref(&A::print_i));
	cout<<endl;

	for_each(va.begin(), va.end(), boost::mem_fn(&A::print_j));
	cout<<endl;

	for_each(va.begin(),va.end(),
			boost::bind(&A::print_i, _1));
	cout<<endl;

	int c=count_if(va.begin(),va.end(),
			boost::bind( greater<int>(),
				boost::bind(&A::i, _1), 6));
	cout<<c<<endl;

	c=count_if( va.begin(), va.end(),
			boost::bind( equal_to<int>(),
				boost::bind( modulus<int>(),
					boost::bind(&A::geti,_1), 4), 0));
	cout<<c<<endl;
}
